package com.nfit.service.impl.usersettings;

import com.nfit.dao.UserSettingsMapper;
import com.nfit.entity.UserSettings;
import com.nfit.service.UserSettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Service
public class UserSettingsServiceImpl implements UserSettingsService {
    @Autowired
    private UserSettingsMapper dao;

    @Override
    public List<UserSettings> selectUserSettings(String userId) {
        return dao.selectUserSettings(userId);
    }

    @Override
    @Transactional
    public int saveUserSettings(String userId, Boolean email, Boolean username, Boolean phone) {
        int count = 0;
        dao.deleteUserSetting(userId);
        if (email) {
            count += dao.insertUserSetting(userId, "email", true);
        }
        if (username) {
            count += dao.insertUserSetting(userId, "username", true);
        }
        if (phone) {
            count += dao.insertUserSetting(userId, "phone", true);
        }
        return count;
    }
}
